package com.haozhen

import org.apache.spark.sql.expressions.UserDefinedAggregateFunction

/**
  * @author haozhen
  * @email haozh@ync1.com
  * @date 2020/12/27  15:27
  */
class TypeUnsafeUDAF extends UserDefinedAggregateFunction{
  import org.apache.spark.sql.Row
  import org.apache.spark.sql.expressions.MutableAggregationBuffer
  import org.apache.spark.sql.types.{DataType, DoubleType, StringType, StructType}

  //定义输入数据类型
  override def inputSchema: StructType = new StructType().add("sales",DoubleType).add("saleDate",StringType)

  //定义数据缓存类型
  override def bufferSchema: StructType =  new StructType().add("year2019",DoubleType).add("year2020",DoubleType)

  //定义最终返回结果类型
  override def dataType: DataType = DoubleType

  //对应相同的结果是否有相同的输出
  override def deterministic: Boolean = ???

  //数据缓存的初始化
  override def initialize(buffer: MutableAggregationBuffer): Unit = ???

  //
  override def update(buffer: MutableAggregationBuffer, input: Row): Unit = ???

  override def merge(buffer1: MutableAggregationBuffer, buffer2: Row): Unit = ???

  //计算最终的结果
  override def evaluate(buffer: Row): Any = ???
}
